package org.leo.dm.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

/**
 * 
 * Created on 2015年11月5日
 * <p>
 * Description 线程池
 * <p>
 * Copyright neusoft (c) 2015 .
 * 
 * @author xiao_h
 *
 */
public class ThreadPoolUtil {

	private ExecutorService pool;

	private int threadPoolSize = java.lang.Runtime.getRuntime().availableProcessors();

	public int getThreadPoolSize() {
		return threadPoolSize;
	}

	public ThreadPoolUtil() {
	}

	public void initPool() {
		initPool(0);
	}

	public void initPool(int numberOfThreadsTemp) {
		if (pool == null) {
			if (numberOfThreadsTemp > 0) {
				this.threadPoolSize = numberOfThreadsTemp;
			}
			pool = Executors.newFixedThreadPool(this.threadPoolSize);
		}
	}

	public ExecutorService getPool() {
		initPool(0);
		return pool;
	}

	public void shutdownPool() {
		if (pool != null) {
			pool.shutdown();
		}
	}

}

class ThreadFactoryBuilder implements ThreadFactory {

	@Override
	public Thread newThread(Runnable r) {
		return null;
	}

}